#!/usr/bin/env bash
if [[ "`id -u`" != "0" ]]; then sudo -sE "${0}" "${1}" || exit 1; exit; fi;
f_fail(){ echo -e "\033[31m[FAIL]\033[0m ${1}" >&2; exit 1; }
lst=$(cat '/home/.os/conf/.exec-fpm');

run(){
    for n in ${lst}; do
        echo -e "\033[36m[${1}] ${n}\033[0m";
        systemctl "${1}" "${n}";
    done;
}

if [[ -z "${1}" ]] || [[ "$1" = "restart" ]]; then run 'restart';
elif [[ "$1" = "start" ]]; then run 'start';
elif [[ "$1" = "stop" ]]; then run 'stop';
elif [[ "$1" = "status" ]]; then run 'status';
else f_fail 'usage: fpm.sh [start|stop|restart|status]'; fi;

echo >/dev/null;
